<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<title></title>
<script type="text/javascript">
	Ext.onReady(function(){
		var resultWidth = Ext.get("process-grid").getWidth();
		var userId = '${__SATURN_AUTORITY_USER__.id}';
		var process_instance_id = <%=request.getParameter("process_instance_id")%>;
		var activity_instance_id = <%=request.getParameter("activity_instance_id")%>;
		var store = new Ext.data.JsonStore({
		    url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.manager::/queryModule/action/QueryWorkitemList.action',
		    root: 'result',
		    totalProperty:'count',
		    fields: [
	               {name: 'workitem_id', mapping: 'workitem_id'},
	               {name: 'workitem_name', mapping: 'name'},
	               {name: 'workitem_state', mapping: 'state'},
	               {name: 'process_instance_name', mapping: 'process_instance_name'},
	               {name: 'workitem_is_timeout', mapping: 'is_timeout'}, 
		    	   {name: 'workitem_start_time', mapping: 'start_time'},
		    	   {name: 'workitem_end_time', mapping: 'end_time'}
	           ]
		});
		
	    var grid = new Ext.grid.GridPanel({
	    	frame:true,
	        title: '工作项列表',
       	    store: store,
       	    bodyStyle:'width:100%',
	        columns: [	 
	            {header: "工作项ID", width:resultWidth*0.1, dataIndex: 'workitem_id', sortable: true},
	            {header: "工作项名称", width:resultWidth*0.15, dataIndex: 'workitem_name', sortable: true,renderer:showOp},
	            {header: "当前状态", width:resultWidth*0.1, dataIndex: 'workitem_state', sortable: true,renderer:showState},
	            {header: "流程实例名称", width:resultWidth*0.15, dataIndex: 'process_instance_name', sortable: true},
	            {header: "是否超时", width:resultWidth*0.1, dataIndex: 'workitem_is_timeout', sortable: true,renderer:timeout},
	            {header: "工作项开始时间", width:resultWidth*0.15, dataIndex: 'workitem_start_time', sortable: true},
	            {header: "工作项结束时间", width:resultWidth*0.15, dataIndex: 'workitem_end_time', sortable: true}
	        ],
	        renderTo:'process-grid',
	        height:600,
	        frame:true,
	        loadMask: {msg:'正在加载数据，请稍侯……'}, 
	        tbar:new Array(
			   new Ext.Toolbar.Button({
						   text:'返回',
						   xtype:"button" ,
						   tooltip:"返回上一个页面" ,
						   handler: goBack,
						   scope :this})	   
		 ),
	        bbar: new Ext.PagingToolbar({ 
		            pageSize: 20, 
		            store: store, 
		            displayInfo: true, 
		            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
		            emptyMsg: "没有数据显示" 
		    }) 
    });
   
   	store.load({params: {start:0,limit:20,process_instance_id:process_instance_id,activity_instance_id:activity_instance_id}});
   	store.on('beforeload',function(){
	    Ext.apply(this.baseParams,{process_instance_id:process_instance_id,activity_instance_id:activity_instance_id});
    });
   	function showOp(value,cellmeta,record){	
			return "<a href='javascript:showWorkitemInfo("+record.data["workitem_id"]+")'>"+value+"</a>";	
	}
	function goBack(){	
		window.history.back();
	}
	function showState(value){
		if(value=='10')
			return "运行";
		if(value=='12')
			return "完成";
	}
	function timeout(value){
		if(value=='Y'){
			return "是";
		}else{
			return "否";
		}
	}
});

function showWorkitemInfo(workitem_id){
	  var store = new Ext.data.JsonStore({
		    url: "${pageContext.request.contextPath}/edu.ccut.saturn.workflow.manager::/queryModule/action/QueryWorkitemInfo.action",
		    root: 'result',
		    fields: [
	               {name: 'workitem_id', mapping: 'workitem_id'},
	               {name: 'name', mapping: 'name'},
		    	   {name: 'process_define_name', mapping: 'process_define_name'},
	               {name: 'state', mapping: 'state'},
	               {name: 'priority', mapping: 'priority'},
	               {name: 'is_timeout', mapping: 'is_timeout'},
	               {name: 'limit_number', mapping: 'limit_number'},
	               {name: 'limit_number_description', mapping: 'limit_number_description'},
	               {name: 'start_time', mapping: 'start_time'},
	               {name: 'participant', mapping: 'assistant_name'},
	               {name: 'end_time', mapping: 'end_time'},
	               {name: 'activity_instance_name', mapping: 'activity_instance_name'},
	               {name: 'process_instance_name', mapping: 'process_instance_name'}
	           ]
		});
	    store.load({params: {workitem_id:workitem_id}});
	    
	    store.on('load',function(){
	    	record = store.getAt(0);
	    var panel = new Ext.FormPanel({
	        frame:true,
	        bodyStyle:'padding:5px 5px 0',
	       items: [{
	            layout:'column',
	            items:[{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '工作项ID',
		                    name: 'workitem_id',
		                    id: 'workitem_id',
		                    value:record.data["workitem_id"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '工作项名称',
		                    name: 'name',
		                    id: 'name',
		                    value:record.data["name"],
		                    disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '业务流程名称',
		                    name: 'process_define_name',
		                      value:record.data["process_define_name"],
		                    id: 'process_define_name',
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '当前状态',
		                    name: 'state',
		                    id: 'state',
		                     value:record.data["state"]=='12'?"完成":"运行",
		                     disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '优先级',
		                    name: 'priority',
		                    id: 'priority',
		                    value:record.data["priority"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '是否超时',
		                    name: 'is_timeout',
		                    id: 'is_timeout',
		                     value:record.data["is_timeout"]=='Y'?"是":"否",
		                     disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '限制时间',
		                    name: 'limit_number',
		                    id: 'limit_number',
		                     value:record.data["limit_number"],
		                   disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '限制时间描述',
		                    name: 'limit_number_description',
		                    id: 'limit_number_description',
		                     value:record.data["limit_number_description"],
		                    disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '流程启动时间',
		                    name: 'start_time',
		                    id: 'start_time',
		                     value:record.data["start_time"],
		                    disabled:true
		                },{
		                    xtype:'textfield',
		                    fieldLabel: '流程实例名称',
		                    name: 'process_instance_name',
		                    id: 'process_instance_name',
		                    value:record.data["process_instance_name"],
		                    disabled:true

	           		 }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '流程结束时间',
		                    name: 'end_time',
		                    id: 'end_time',
		                    value:record.data["end_time"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '活动实例名称',
		                    name: 'activity_instance_name',
		                    id: 'activity_instance_name',
		                    value:record.data["activity_instance_name"],
		                   disabled:true
		                }]
	            }] 
        }], buttons: [{
	            text: '返回',
	            handler:function(){
	            	window.close();
	            }
       		 }]
	    });
			
		    var window = new Ext.Window({
				title: '工作项实例信息',
				width: 700,
				height:250,
				minWidth: 300,
				minHeight: 200,
				layout: 'fit',
				plain:true,
				items:panel,
				buttonAlign:'center',
				modal:true
			});
			window.show();
	    })
	
		
	}
</script>
<div id='form-ct' width='100%'></div>
<div id='process-grid' width='100%'></div>
</head>
</html>